
//
//  UINavigationController+LCNavigationController.m
//  
//
//  Created by admin on 2016/12/26.
//  Copyright © 2016年 LC. All rights reserved.
//

#import "LCNavigationController.h"


@interface  LCNavigationController ()<UIGestureRecognizerDelegate>

@end

@implementation LCNavigationController

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
//    [self setNavigationBarHidden:YES animated:animated];
}

-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
//    [self setNavigationBarHidden:NO animated:animated];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationController.navigationItem.hidesBackButton = YES;//隐藏系统的返回按钮

    [self.navigationBar setBarTintColor:RGBColor(228, 83, 77)];//设置navbar底色
    
    [self.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor], NSForegroundColorAttributeName, [UIFont systemFontOfSize:20], NSFontAttributeName,nil]];
    self.navigationBar.tintColor = [UIColor whiteColor];//设置按钮颜色

//    self.hidesBottomBarWhenPushed  = YES;
//    [self setNavigationBarHidden:YES animated:YES];
    // 获取系统自带滑动手势的target对象
    self.interactivePopGestureRecognizer.delegate = self;
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(pushAccLoginNotification:) name:@"LCPUSHAccLoginNotification" object:nil];
}
- (void)dealloc {
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"LCPUSHAccLoginNotification" object:nil];
}
- (void)pushAccLoginNotification:(NSNotification *)notification  {
    UIStoryboard *sb = [UIStoryboard storyboardWithName:@"AccLogin" bundle:nil];
    UIViewController *viewController = [sb instantiateInitialViewController];
    [self showViewController:viewController sender:nil];
}
// 什么时候调用：每次触发手势之前都会询问下代理，是否触发。
// 作用：拦截手势触发
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
{
    NSLog(@"self.childViewControllers.lastObject = %@", self.childViewControllers.lastObject);
    // 注意：只有非根控制器才有滑动返回功能，根控制器没有。
    // 判断导航控制器是否只有一个子控制器，如果只有一个子控制器，肯定是根控制器
    if ([self.childViewControllers.lastObject isKindOfClass:[LSZFindOutMoreVC class]]) {
        return NO;
    }
    
    if (self.childViewControllers.count == 1) {
        // 表示用户在根控制器界面，就不需要触发滑动手势，
        return NO;
    }
    return YES;
}


- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated{
    if (self.viewControllers.count > 0) {
//        当push的时候,隐藏底部栏.        设置属性必须要写在push操作完成之前
        viewController.hidesBottomBarWhenPushed = YES;
//        [self setNavigationBarHidden:NO animated:YES];
    }
    [super pushViewController:viewController animated:animated];
}



@end
